package org.dfg.corejava.designPattern.iterator;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Aggregate implements Iterator {

	private List<String> list;
	private int current = 0;

	public Aggregate(String... strs) {
		list = Arrays.asList(strs);
	}

	@Override
	public void first() {
		current = 0;
	}

	@Override
	public void last() {
		current = list.size() > 0 ? 0 : list.size() - 1;
	}

	@Override
	public void next() {
		current = current + 1 > list.size() ? current : ++current;
	}

	@Override
	public <T> T currentItem() {
		return (T) list.get(current);
	}

	@Override
	public boolean isDone() {
		return current + 1 > list.size();
	}

}
